@extends('admin.app')
@section('content')
    <link rel="stylesheet" href="/css/admin/confirm-information.css">

    <div class="mian-container">
        <div class="confirm-information">
            <div class="confirm-header">
                <div class="confirm-top">
                    <img src={{"/uploads/images/company-logo/".$corpid.".png"}}>
                </div>

                <div class="confirm-list weui-cells">
                    <div class="weui-cell">
                        <div class="weui-cell__hd">
                            <i class="icon iconfont icon-qiye"></i>
                        </div>
                        <div class="weui-cell__hd">
                            <p class="p-length">企业名称</p>
                        </div>
                        <div class="weui-cell__ft">
                            <div class="needsclick company-name" contenteditable="true" placeholder='请输入企业名称'  id="name" >{{$company->name}}</div>
                        </div>
                    </div>
                    <div class="weui-cell">
                        <div class="weui-cell__hd">
                            <i class="icon iconfont icon-yinliang"></i>
                        </div>
                        <div class="weui-cell__hd">
                            <p class="p-length">宣传语</p>
                        </div>
                        <div class="weui-cell__ft">
                            <div class="needsclick propaganda-con" contenteditable="true" placeholder='请输入宣传语'  id="slogan">{{$company->slogan}}</div>
                        </div>
                    </div>
                </div>
            </div>

        {{--        <div class="confirm-list weui-cells">
                    <div class="weui-cell">
                        <div class="weui-cell__hd">
                            <i class="icon iconfont icon-lianjie"></i>
                        </div>
                        <div class="weui-cell__hd">
                            <p class="p-length">生成链接</p>
                        </div>
                        <div class="weui-cell__ft">
                            <p id="text">www.123456.com</p><p id="copy">复制</p>
                        </div>
                    </div>
                </div>--}}
                <div class="a-link">
                    <input type="submit" class="weui-btn weui-btn_color" value='登录' id="submit">
                </div>

        </div>
    </div>
    <script>
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        function ajax_init_create() {
            var corpid='{{$corpid}}'
            var url='/admin/init/' + 'corpid';
            var name = $("#name").text();
            var slogan = $("#slogan").text();
            $.ajax({
                type: 'put',
                cache: 'false',
                url: url,
                data: 'name=' + name + '&slogan=' + slogan,
                dataType: 'json',
                success: function (data) {
                    if (data.status == 'success') {
                        $.toptip(data.msg,'success');
                        window.location.href= data.redirectUrl;
                    } else {
                        $.toptip(data.msg,'error');
                        window.location.href= data.redirectUrl;
                    }
                },
                error: function () {
                    $.toptip('网络异常请重试','warning');
                }
            });
        }
        //表单验证
        $("#submit").click(function () {
            var first = $(".company-name").text().length;
            var last = $(".propaganda-con").text().length;

            if (first==0||first >30) {
                $.toptip('请保持公司名称在30字内！');
                return false;/*阻止表单提交*/
            } else if (last==0||last>50) {
                $.toptip('请保持宣传语在50字内！')
                return false;/*阻止表单提交*/
            } else {
                ajax_init_create()
                return true;
            }
        });
        //点击复制链接
        $("#copy").on("click",function(){
            var  val = $("#text").text();
            Clipboard.copy(val);
        });
    </script>
@endsection
